package com.example.weixinpayment.controller;

import com.example.weixinpayment.constant.enums.OrderStatus;
import com.example.weixinpayment.entity.OrderInfo;
import com.example.weixinpayment.result.Result;
import com.example.weixinpayment.service.OrderInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: weixin-payment
 * @description: 订单控制器
 * @author: LiuZhuzheng
 * @create: 2021-12-30 18:40
 **/
@Api(tags = "订单管理")
@CrossOrigin
@RestController
@RequestMapping("/api/order-info")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation("按创建时间倒序查找订单列表")
    @GetMapping("/list")
    public Result listOrderByCreateTimeDesc(){
        List<OrderInfo> orderInfoList = orderInfoService.listOrderByCreateTimeDesc();

        return Result.success().data("list", orderInfoList);
    }

    @ApiOperation("查询本地订单状态")
    @GetMapping("/query-order-status/{orderNo}")
    public Result queryOrderStatus(@PathVariable String orderNo){
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        if (OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return Result.success().setMessage("支付成功");
        }

        return Result.success().setCode(101).setMessage("支付中......");
    }
}
